#ifndef SIMUBOARD_LEDWIDGET_HPP
#define SIMUBOARD_LEDWIDGET_HPP

#include <FL/Fl_Box.H>
#include <string>

class Fl_PNG_Image; // PNG 前向声明
class Fl_Image;

class LEDWidget : public Fl_Box
{
public:
    // 构造：传入顶部与底部文字
    LEDWidget(int x, int y, int w, int h, const char* top_text, const char* bottom_text);
    ~LEDWidget() override;

    void set_state(bool on);
    [[nodiscard]] bool get_state() const;

    void set_top_text(const char* s)
    {
        top_text_ = s ? s : "";
        redraw();
    }

    void set_bottom_text(const char* s)
    {
        bottom_text_ = s ? s : "";
        redraw();
    }

    static Fl_PNG_Image* s_img_on; // 共享图片（开）
    static Fl_PNG_Image* s_img_off; // 共享图片（关）

protected:
    void draw() override;

private:
    bool is_on = false;
    std::string top_text_;
    std::string bottom_text_;
    int top_h_ = 20;
    int bottom_h_ = 18;

    // 缓存按当前尺寸缩放后的图像，避免每帧缩放
    Fl_Image* cached_img_ = nullptr;
    int cached_w_ = 0;
    int cached_h_ = 0;
    bool cached_on_ = false;
};

#endif //SIMUBOARD_LEDWIDGET_HPP
